try :
    if dellist:
        cmds.delete( dellist )
        dellist = []
except :
    dellist = []
Lfootmain = cmds.createNode( 'distanceBetween' , n = 'Lfootmain' )    
Rfootmain = cmds.createNode( 'distanceBetween' , n = 'Rfootmain' ) 
LRfoot = cmds.createNode( 'distanceBetween' , n = 'LRfoot' ) 
dellist.append( Lfootmain ) 
dellist.append( Rfootmain ) 
dellist.append( LRfoot )

cmds.connectAttr('main.t' ,Lfootmain+'.p1' )
cmds.connectAttr('L_foot.t' ,Lfootmain+'.p2' )
LfootmainDist = cmds.getAttr( Lfootmain+'.d' )

cmds.connectAttr('main.t' ,Rfootmain+'.p1' )
cmds.connectAttr('R_foot.t' ,Rfootmain+'.p2' )
RfootmainDist = cmds.getAttr( Rfootmain+'.d' )

cmds.connectAttr('L_foot.t' ,LRfoot+'.p1' )
cmds.connectAttr('R_foot.t' ,LRfoot+'.p2' )
LRfootDist = cmds.getAttr( LRfoot+'.d' )

str = '''
float $mainZ = `getAttr -t (frame) main.tz`;
float $mainZ1 = `getAttr -t (frame-1) main.tz`;
if ( Rfootmain.d > 2 || R_foot.ty != 0 || LRfoot.d > 4 )
{  
    float $pos = `getAttr -t (frame-5) main.tz`;
    R_foot.ty = max( 0 , sin( $mainZ )*3 );    
    R_foot.tz = $mainZ  + sin($mainZ1 - $mainZ)*3;   
}

if ( LRfoot.d > 3 || L_foot.ty != 0 )
{
    L_foot.ty = max( 0 , sin( $mainZ+5 )*3 );    
    L_foot.tz = $mainZ
}
'''
exp = cmds.expression( s=str , ae = 1 )
dellist.append( exp )
